package cz.via.facepalm.calendar;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class LoginActivity extends Activity 
{
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.login);
		
		Button button = (Button) findViewById(R.id.login_btn);
		button.setOnClickListener(new View.OnClickListener() 
		{
			public void onClick(View v) 
			{			
				EditText usernameInput = (EditText)findViewById(R.id.username);
				EditText passwordInput = (EditText)findViewById(R.id.password);
				String username = usernameInput.getText().toString();
				String password = passwordInput.getText().toString();
				
				//Check credentials
				if(true)
				{
					Bundle credentials = new Bundle();
					credentials.putString("username", username);
					credentials.putString("password", password);
					
					Intent intent = new Intent(LoginActivity.this,
							CalendarExpandableList.class);
					intent.putExtras(credentials);
					startActivity(intent);
				}
				else
				{
					((TextView)findViewById(R.id.username)).setText("Invalid username or password");					
				}
			}
		});

		// String [] groupsSource = new String[]{"apg","ops"};
		// String [] typesSource = new String[]{"lecture","exercise"};
		// String [] projectsSource = new String[]{"project 1","project 2"};
		//
		// Spinner groups = (Spinner)findViewById(R.id.groups);
		// ArrayAdapter<String> adapter = new ArrayAdapter<String>(
		// this, android.R.layout.simple_spinner_item, groupsSource);
		// adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		// groups.setAdapter(adapter);
		//
		// Spinner types = (Spinner)findViewById(R.id.types);
		// ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(
		// this, android.R.layout.simple_spinner_item, typesSource);
		// adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		// types.setAdapter(adapter2);
		//
		// Spinner projects = (Spinner)findViewById(R.id.projects);
		// ArrayAdapter<String> adapter3 = new ArrayAdapter<String>(
		// this, android.R.layout.simple_spinner_item, projectsSource);
		// adapter3.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		// projects.setAdapter(adapter3);		

		// setContentView(R.layout.calendarexpladablelist);
		//
		// tasks = new CalendarTask[2];
		// tasks[0] = new CalendarTask("Via deadline",new
		// String[]{"7:30","1","12"},
		// "FacePalm","KN:E-301","Seminar","VIA project");
		// tasks[1] = new CalendarTask("PSI seminar",new
		// String[]{"10:00","5","12"},
		// "FacePalm","KN:E-107","toaleta","hygiena");
		//
		// SimpleExpandableListAdapter expListAdapter = new
		// SimpleExpandableListAdapter(
		// this,
		// createGroupList(),
		// R.layout.group_row,
		// new String[] { "Hour", "Date", "Title" },
		// new int[] { R.id.row_hour,R.id.row_date,R.id.row_title },
		// createChildList(),
		// R.layout.child_row,
		// new String[] {"Subname","Subvalue"},
		// new int[] { R.id.grp_name, R.id.grp_value}
		// );
		// ExpandableListView v = (ExpandableListView)findViewById(R.id.expand);
		// v.setAdapter(expListAdapter);
		// }
		//
		//
		// @SuppressWarnings("unchecked")
		// private List createGroupList()
		// {
		// ArrayList result = new ArrayList();
		// for( int i = 0 ; i < tasks.length ; ++i ) {
		// HashMap m = new HashMap();
		// m.put( "Date",tasks[i].date[1]+'.'+tasks[0].date[2]+'.' );
		// m.put( "Hour",tasks[i].date[0]);
		// m.put( "Title",tasks[i].title);
		// result.add( m );
		// }
		// return (List)result;
		// }
		//
		// @SuppressWarnings("unchecked")
		// private List createChildList()
		// {
		// ArrayList result = new ArrayList();
		// for( int i = 0 ; i < tasks.length ; ++i )
		// {
		// ArrayList secList = new ArrayList();
		//
		// HashMap child1 = new HashMap();
		// child1.put( "Subname", "Group:" );
		// child1.put( "Subvalue", tasks[i].group );
		// secList.add( child1 );
		//
		// HashMap child2 = new HashMap();
		// child2.put( "Subname", "Place:" );
		// child2.put( "Subvalue", tasks[i].place );
		// secList.add( child2 );
		//
		// HashMap child3 = new HashMap();
		// child3.put( "Subname", "Type:" );
		// child3.put( "Subvalue", tasks[i].type );
		// secList.add( child3 );
		//
		// HashMap child4 = new HashMap();
		// child4.put( "Subname", "Project:" );
		// child4.put( "Subvalue", tasks[i].project );
		// secList.add( child4 );
		//
		// result.add( secList );
		// }
		// return (List)result;
	}
}